package Exit;

/**
 * @author 王艺锡
 * @version 1.0
 * 线程终止
 */
public class ThreadExit {
    public static void main(String[] args) {
        T t = new T();
        t.start();

        //主线程休眠10s
        try {
            Thread.sleep(10 * 1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        t.setFlag(false);
    }
}
class T extends Thread{
    private int count = 0;
    private boolean flag = true;
    @Override
    public void run() {
       while (flag){
           System.out.println("hello" + (++count));

           try {
               Thread.sleep(50);
           } catch (InterruptedException e) {
               e.printStackTrace();
           }
       }
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }
}
